#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define LL long long 
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size

using namespace std;

const int N = 2e5 + 10;

int n, m;
int w[N], q[N], f[N];

int main() {
	in(n), in(m);
	
	flr (i, 1, n) in(w[i]);
	
	int hh = 0, tt = 0;
	flr (i, 1, n) {
	    if (q[hh] < i - m) hh ++ ;
	    f[i] = f[q[hh]] + w[i];
	    while (hh <= tt && f[q[tt]] >= f[i]) tt --;
	    q[ ++ tt] = i;
	}
	
	int res = 1e9;
	flr (i, n - m + 1, n) res = min(res, f[i]);
	
	out(res);
	
	return 0;
}